#include "pe_cclabelttf.h"

#include "PE_CCLabelTTF.h"
#include "PE_CCLabelTTF.h"
#include "CCQTSceneDirector.h"
#include "cocoext\cclabelttf_ext.h"

PE_CCLabelTTF::PE_CCLabelTTF(QtVariantPropertyManager *variantManager):PE_CCRGBAProtocol(variantManager)
{
    
}

QtProperty *PE_CCLabelTTF::initUI()
{
	addProperty(QVariant::String , "Text");
	addProperty(QVariant::String , "FontName");
	addProperty(QVariant::Int , "FontSize");
    return PE_CCRGBAProtocol::initUI();
}

void PE_CCLabelTTF::refresh()
{
	CCLabelTTF_Ext * cnode = dynamic_cast<CCLabelTTF_Ext*>(CCQTSceneDirector::sharedSceneDirector()->CurrentCNode());
	if (cnode == NULL) return;
	int size = cnode->getFontSize();
	QString name = QString(cnode->fontName());

	Property("Text")->setValue(cnode->getString());
 	Property("FontSize")->setValue(size);
 	Property("FontName")->setValue(name);

    PE_CCRGBAProtocol::refresh();
        
}

void PE_CCLabelTTF::valueChanged(QtProperty *property, QVariant variant)
{
	//CCLabelTTF * cnode = (CCLabelTTF*)CCQTSceneDirector::sharedSceneDirector()->CurrentCNode();
    CCLabelTTF_Ext * cnode = dynamic_cast<CCLabelTTF_Ext*>(CCQTSceneDirector::sharedSceneDirector()->CurrentCNode());

	if (property == Property("Text"))
	{
		cnode->setString(variant.value<QString>().toLocal8Bit());

	}
	else if (property == Property("FontName"))
	{
// 		CCLabelTTF * newnode = CCLabelTTF::labelWithString(cnode->getString() , variant.value<QString>().toLocal8Bit(), cnode->getFontSize());
// 		CCQTSceneDirector::sharedSceneDirector()->changeCurrent(newnode );
		cnode->setFontName(variant.value<QString>().toLocal8Bit());
		cnode->recreateLabel();
	}
	else if (property == Property("FontSize"))
	{
// 		CCLabelTTF * newnode = CCLabelTTF::labelWithString(cnode->getString() , cnode->fontName(), variant.value<int>());
// 		CCQTSceneDirector::sharedSceneDirector()->changeCurrent(newnode );
// 		
		cnode->setFontSize(variant.value<int>());
		cnode->recreateLabel();
	}
    PE_CCRGBAProtocol::valueChanged(property, variant);
}
